﻿using DeepEarth.Map.Core;
using System.Collections.Generic;
using System;
using System.Linq;
using DeepEarth.Map.Core.Tiling;
namespace DeepEarth.Map.TileSources
{
    public class OSMTileSourceFactory : BaseTileSourceFactory
    {
        public static readonly MapMode StreetMap = new MapMode("OSM", "OSM", "OSM", "Open Street Map");
        
		private static readonly MapMode[] _availableModes = new[] { StreetMap};
		
        public override IList<MapMode> AvailableModes { get { return _availableModes; } }
        private static readonly OSMTileSource StreetsTileSource = new OSMTileSource(StreetMap);

		public static bool IsValidMode(MapMode mode)
		{
			return _availableModes.Contains(mode);
		}

		public static void ValidateMode(MapMode mode)
		{
			if (!IsValidMode(mode))
				throw new ArgumentOutOfRangeException(String.Format("Map mode '{0}:{1}' is not valid for the OSM provider",
				                                                    mode.ProviderKey,
				                                                    mode.Identifier));
		}

		public override BaseTileSource CreateTileSource(MapMode mode)
		{
			mode = ValidateAndCoerceMapMode(mode);
            if (mode == StreetMap) 
                return StreetsTileSource;
			return new OSMTileSource(mode);
		}
    }
}
